package com.gyg.controller;


import com.gyg.returns.RespEntity;
import com.gyg.service.CloudCollectionService;
import com.gyg.vo.param.CollectionParam;
import com.gyg.vo.param.UpdateCollectionParam;
import com.gyg.vo.result.CollectionResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 文件收藏表 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/cloud-collection")
@Slf4j
@Api(value = "文件收藏", tags = "文件收藏")
public class CloudCollectionController {

    @Resource
    private CloudCollectionService cloudCollectionService;

    @PostMapping("/add")
    @ApiOperation(value = "添加收藏")
    public RespEntity cloudAddCollection (@RequestBody CollectionParam collectionParam) {
        RespEntity respEntity = cloudCollectionService.fileAddCollection(collectionParam);
        return respEntity;
    }


    @GetMapping("/list")
    @ApiOperation(value = "收藏列表")
    @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "userId", value = "用户id", required = true)
    public RespEntity<CollectionResult> collectionList(@RequestParam(value = "userId", required = true) Integer userId) {
        RespEntity<CollectionResult> respEntity = cloudCollectionService.collectionList(userId);
        return respEntity;
    }

    @PutMapping("/update")
    @ApiOperation(value = "编辑收藏文件")
    public RespEntity updateCollection(@RequestBody UpdateCollectionParam updateCollectionParam) {
        RespEntity respEntity = cloudCollectionService.updateCollection(updateCollectionParam);
        return respEntity;
    }

    @DeleteMapping("/cancel")
    @ApiOperation(value = "取消收藏")
    public RespEntity deleteCollection(@RequestBody CollectionParam collectionParam) {
        RespEntity respEntity = cloudCollectionService.cancelCollection(collectionParam);
        return respEntity;
    }

}
